//
//  FoodTableViewCell.m
//  美食百科
//
//  Created by dllo on 16/2/3.
//  Copyright © 2016年 doll. All rights reserved.
//

#import "FoodTableViewCell.h"

@interface FoodTableViewCell()

@property(nonatomic,assign)CGFloat height;
@end

@implementation FoodTableViewCell
- (void)dealloc
{
    [_titleLabel release];
    [_contentLabel release];
    [super dealloc];
}


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = [UIColor redColor];
        self.titleLabel.font = [UIFont systemFontOfSize:23];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.textColor = self.color;

        self.contentLabel.numberOfLines = 0;
        [self.contentView addSubview:self.contentLabel];
        [_contentLabel release];

    }
    
    return self;
}



-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.titleLabel.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, 30);
    
    //计算详情文字的高度
    CGFloat result = [FoodTableViewCell heightOfSelfSuit:self.contentLabel.text font:[UIFont systemFontOfSize:17] width:self.contentView.frame.size.width - 20];
    
    self.contentLabel.frame = CGRectMake(self.titleLabel.frame.origin.x,self.titleLabel.frame.origin.y+self.titleLabel.frame.size.height+10, self.contentView.frame.size.width -self.titleLabel.frame.origin.x*2, result);
}

+(CGFloat)heightOfSelfSuit:(NSString *)text font:(UIFont *)font width:(CGFloat)width
{
    CGSize size = CGSizeMake(width, MAXFLOAT);
    
    NSDictionary *style = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil];
    
    CGRect result = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:style context:nil];
    
    return result.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
